package bajw;

import it.sauronsoftware.jave.AudioAttributes;
import it.sauronsoftware.jave.Encoder;
import it.sauronsoftware.jave.EncoderException;
import it.sauronsoftware.jave.EncodingAttributes;
import it.sauronsoftware.jave.InputFormatException;

import java.awt.image.BufferedImage;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Set;
import java.util.TreeMap;

import javax.imageio.ImageIO;

import org.junit.Test;

import com.sbl.bajw.common.web.BaiduMsgPush;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.image.codec.jpeg.JPEGImageEncoder;

public class text1 {
	
	public void testfile() throws IOException {
		
		String targetImagePath = "d:/t.jpg";
		String resultImagePath = "d:/t1.jpg";
	        
	 	ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        BufferedImage bufferedImage = ImageIO.read(new File(targetImagePath));
        JPEGEncodeParam parm = JPEGCodec.getDefaultJPEGEncodeParam(bufferedImage);
        parm.setQuality(0.05f, false);
        JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(byteArrayOutputStream, parm);  
        encoder.encode(bufferedImage); 
        
        FileOutputStream resultOut = new FileOutputStream(resultImagePath);
        resultOut.write(byteArrayOutputStream.toByteArray());
        resultOut.flush();
        resultOut.close();
	}
	
//	@Test
	public void testBaidugps() throws Exception{
		LinkedHashMap<String, String> column = new LinkedHashMap<String, String>();
		column.put("code", "编码");
		column.put("name", "监控室名称");
		column.put("address", "监控室地址");
		column.put("lon", "经度");
		column.put("lat", "纬度");
		column.put("chargeMan", "责任人");
		column.put("phone", "联系电话");
		column.put("cameraNum", "摄像头数量");
		column.put("buildingCode", "楼栋编码");
		column.put("watchManNum", "持证上岗人数");
		column.put("createTime", "采集时间");
		column.put("note", "备注");
		column.put("isQuelity", "是否合格");
		column.put("policeStationName", "派出所");
		column.put("communityName", "社区");
		column.put("creatername", "采集人");
		column.put("auditname", "审核人");
		column.put("audittime", "审核时间");
		column.put("reason", "审核原因");
		column.put("audituserno", "采集人账号");
		column.put("auditusercardid", "采集人身份证号");
		column.put("cameraNormalNum", "正常使用摄像头数量");
		column.put("updater", "更新人");
		column.put("updatetime", "更新时间");
		column.put("installDateStr", "安装时间");
		column.put("createdeptname", "采集单位");
		
		Iterator<String> key = column.keySet().iterator();
		
		while(key.hasNext()){
			System.out.println(key.next());
		}
	}
	
	
	public void face(){
		 String str="http://183.62.134.180:35180/frfacework";
	        String filePath="D:\\testface\\6.jpg";
	        try {
	            URL url=new URL(str);
	            HttpURLConnection connection=(HttpURLConnection)url.openConnection();
	            connection.setDoInput(true);
	            connection.setDoOutput(true);
	            connection.setRequestMethod("POST");
	            connection.setRequestProperty("content-type", "application/octet-stream");
	            BufferedOutputStream  out=new BufferedOutputStream(connection.getOutputStream());
	            
	            //读取文件上传到服务器
	            File file=new File(filePath);
	            FileInputStream fileInputStream=new FileInputStream(file);
	            byte[]bytes=new byte[1024];
	            int numReadByte;
	            while((numReadByte=fileInputStream.read(bytes,0,1024))>0)
	            {
	                out.write(bytes, 0, numReadByte);
	            }

	            out.flush();
	            fileInputStream.close();
	            DataInputStream in=new DataInputStream(connection.getInputStream());
	            InputStreamReader ireader = new InputStreamReader(in);
	            BufferedReader reader = new BufferedReader(ireader);
	            
	            String result = "";
	            String line = "";
	            while(line != null){
	            	result += line;
	            	line = reader.readLine();
	            }
	            System.out.println(result);
	            
	        } catch (Exception e) {
	            e.printStackTrace();
	        }
	}
	
	@Test
	public void armToMp3(){
		File arm = new File("C:\\Users\\Administrator\\Desktop\\新建文件夹\\18566760984_20150514100710.amr");
		File mp3 = new File("C:\\Users\\Administrator\\Desktop\\新建文件夹\\18566760984_20150514100710.mp3");
		AudioAttributes audio = new AudioAttributes();
		Encoder encoder = new Encoder();
		
		audio.setCodec("libmp3lame");
		EncodingAttributes attrs = new EncodingAttributes();
		attrs.setFormat("mp3");
		attrs.setAudioAttributes(audio);
		
		try {
			encoder.encode(arm, mp3, attrs);
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (InputFormatException e) {
			e.printStackTrace();
		} catch (EncoderException e) {
			e.printStackTrace();
		}
	}
}
